package yxy.game.pm2.bean.db.newDao;

import yxy.apple.db.DbManager;
import yxy.game.pm2.bean.db.po.TitlePo;

import java.util.ArrayList;
import java.util.List;

/**
 * @author James
 * @date 2022/1/24 20:27
 **/
public class TitleDAO {
    private static final String
            ADD_ONE = "replace into `title` (`pCode`, `value`) values (?,?)",
            SELECT_ALL = "select * from `title` where `pCode` = ?";

    public static List<TitlePo> getList(String playerCode) {
        return DbManager.instance().executeQueryObjectList(SELECT_ALL, new Object[]{playerCode}, TitlePo.builder);
    }

    public static boolean replace(List<TitlePo> titlePoList) {
        List<Object[]> list = new ArrayList<>();
        for (TitlePo titlePo : titlePoList) {
            Object[] objects = new Object[]{titlePo.getPlayerCode(),titlePo.getValue()};
            list.add(objects);
        }
        int[] ints = DbManager.instance().executeBatchCommand(ADD_ONE, list);
        return ints.length == titlePoList.size();
    }
}
